package com.fzu.ess.sys.utils;

import com.fzu.ess.sys.entity.Menu;
import com.fzu.ess.sys.entity.Role;

import java.util.*;

/**
 * Created by ercha on 2015/10/16.
 */
public class RoleUtils {

    public static Set<String> getRoleNames(Set<Role> roleSet){
        Set<String> roleNames = new HashSet<>();
        if(roleSet == null) return null;
        Iterator it = roleSet.iterator();
        while(it.hasNext()){
            roleNames.add(((Role)it.next()).getName());
        }
        return roleNames;
    }

    public static Set<String> getRoleNames(List<Role> roleList){
        Set<String> roleNames = new HashSet<>();
        if(roleList == null) return null;

        for(Role role: roleList){
            roleNames.add(role.getName());
        }
        return roleNames;
    }

    public static List<Menu> getMenuList(List<Role> roleList){
        List<Menu> menuList = new ArrayList<>();
        if(roleList == null) return null;
        for(Role role: roleList){
            menuList.addAll(role.getMenuList());
        }
        return menuList;
    }

}
